import {Suspense} from "react"
import { Route, Switch, NavLink, Link,Redirect } from 'react-router-dom'
let RouterView = (props)=>{
     console.log(props)
     let {RouterList} = props
     // 过滤出重定向和非重定向
     let routerList = RouterList.filter((item,index)=>{ // 正常的路由
         return !item.to
     })
     let redrict = RouterList.filter((item,index)=>{ // 正常的路由
        return item.to
    })[0]
    return (
        <Suspense fallback={<div>...加载中</div>}>
            <Switch>
                {
                    routerList&&routerList.length?routerList.map((item,index)=>{
                        return <Route path={item.path} key={index} render={(routerProps)=>{
                                return <item.component {...routerProps}></item.component>
                        }}></Route>
                    }):"暂无路由"
                }
                {
                    redrict?<Redirect to={redrict.to} from={redrict.from}></Redirect>:"暂无重定向"
                }

            </Switch>
        </Suspense>
    )

}
export default RouterView